<template>
	<view>
		<view class="address" v-for="(v, i) in addressList" :key="i">
			<view class="">
				昵称： {{ v.nickname }}--tel: {{ v.tel }}
			</view>
			<view class="">
				{{ i === 0 ? '默认地址': "地址" }}： {{ v.address }}
			</view>
			<button v-if="i!==0">设为默认地址</button>
			<button @click="deleteAddress(v.id)" type="warn">删除</button>
			{{v.id}}
		</view>
		
		
		<navigator url="/pages/addressAdd/addressAdd">新增收获地址</navigator>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				addressList: []
			};
		},
		methods: {
			async getAddressList() {
				const resp = await uni.request({
					url: 'http://localhost:3000/addressList'
				})
				this.addressList = resp.data
			},
			async deleteAddress(id) {
				await uni.request({
					url: 'http://localhost:3000/addressList/' + id,
					method: 'DELETE'
				});
				this.getAddressList()
			}
		},
		onLoad() {
			this.getAddressList();
			
			// uni.request({
			// 	url: 'http://localhost:3000/addressList/1685523336142',
			// 	method: 'PUT',
			// 	data: {
			// 		nickname: '呵呵',
			// 		tel: 110,
			// 		address: '上海'
			// 	}
			// })
		}
	}
</script>

<style lang="scss">
.address {
	border: 2rpx solid #ccc;
	padding: 10rpx;
	border-radius: 20rpx;
	margin: 10rpx 0;
}
</style>